<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge" >
  <title>react-native 第一个demo | 前端.林姐姐</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="React Native Mac环境搭建1、安装Homebrew安装Homebrew是为安装Node.js做前提准备。安装命令:1/usr/bin/ruby -e &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&quot;
注：可以通过下面命令查看Homebrew是否安装成功12brew -vH">
<meta property="og:type" content="article">
<meta property="og:title" content="react-native 第一个demo">
<meta property="og:url" content="http://yoursite.com/2016/10/20/react-native-第一个demo/index.html">
<meta property="og:site_name" content="前端.林姐姐">
<meta property="og:description" content="React Native Mac环境搭建1、安装Homebrew安装Homebrew是为安装Node.js做前提准备。安装命令:1/usr/bin/ruby -e &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&quot;
注：可以通过下面命令查看Homebrew是否安装成功12brew -vH">
<meta property="og:image" content="http://yoursite.com/img/rn-desk.png">
<meta property="og:image" content="http://yoursite.com/img/rn_helloworld.png">
<meta property="og:updated_time" content="2016-10-20T08:07:45.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="react-native 第一个demo">
<meta name="twitter:description" content="React Native Mac环境搭建1、安装Homebrew安装Homebrew是为安装Node.js做前提准备。安装命令:1/usr/bin/ruby -e &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&quot;
注：可以通过下面命令查看Homebrew是否安装成功12brew -vH">
  
    <link rel="alternative" href="/atom.xml" title="前端.林姐姐" type="application/atom+xml">
  
  
    <link rel="icon" href="img/linjie.jpg">
  
  <link rel="stylesheet" href="/css/style.css" type="text/css">
</head>

<body>
  <div id="container">
    <div class="left-col">
    <div class="overlay"></div>
<div class="intrude-less">
	<header id="header" class="inner">
		<a href="/" class="profilepic">
			
			<img lazy-src="undefined" class="js-avatar">
			
		</a>

		<hgroup>
		  <h1 class="header-author"><a href="/">林姐姐</a></h1>
		</hgroup>

		
		<p class="header-subtitle">让未来的你的感谢现在的自己！</p>
		

		
			<div class="switch-btn">
				<div class="icon">
					<div class="icon-ctn">
						<div class="icon-wrap icon-house" data-idx="0">
							<div class="birdhouse"></div>
							<div class="birdhouse_holes"></div>
						</div>
						<div class="icon-wrap icon-ribbon hide" data-idx="1">
							<div class="ribbon"></div>
						</div>
						
						<div class="icon-wrap icon-link hide" data-idx="2">
							<div class="loopback_l"></div>
							<div class="loopback_r"></div>
						</div>
						
						
						<div class="icon-wrap icon-me hide" data-idx="3">
							<div class="user"></div>
							<div class="shoulder"></div>
						</div>
						
					</div>
					
				</div>
				<div class="tips-box hide">
					<div class="tips-arrow"></div>
					<ul class="tips-inner">
						<li>菜单</li>
						<li>標籤</li>
						
						<li>友情链接</li>
						
						
						<li>關於</li>
						
					</ul>
				</div>
			</div>
		

		<div class="switch-area">
			<div class="switch-wrap">
				<section class="switch-part switch-part1">
					<nav class="header-menu">
						<ul>
						
							<li><a href="/">主页</a></li>
				        
							<li><a href="/archives">所有文章</a></li>
				        
							<li><a href="/categories/学习笔记/">学习笔记</a></li>
				        
							<li><a href="/categories/技术摘录/">技术摘录</a></li>
				        
						</ul>
					</nav>
					<nav class="header-nav">
						<div class="social">
							
								<a class="github" target="_blank" href="https://github.com/linjieFE" title="github">github</a>
					        
								<a class="mail" target="_blank" href="mailto:solocode@163.com" title="mail">mail</a>
					        
						</div>
					</nav>
				</section>
				
				
				<section class="switch-part switch-part2">
					<div class="widget tagcloud" id="js-tagcloud">
						<a href="/tags/gulp/" style="font-size: 10px;">gulp</a> <a href="/tags/hexo/" style="font-size: 10px;">hexo</a> <a href="/tags/javascript/" style="font-size: 10px;">javascript</a> <a href="/tags/mac技巧/" style="font-size: 13.33px;">mac技巧</a> <a href="/tags/react/" style="font-size: 10px;">react</a> <a href="/tags/react-native/" style="font-size: 10px;">react-native</a> <a href="/tags/vim/" style="font-size: 10px;">vim</a> <a href="/tags/前题面试题/" style="font-size: 10px;">前题面试题</a> <a href="/tags/学习笔记/" style="font-size: 20px;">学习笔记</a> <a href="/tags/终端/" style="font-size: 10px;">终端</a> <a href="/tags/随笔/" style="font-size: 16.67px;">随笔</a>
					</div>
				</section>
				
				
				
				<section class="switch-part switch-part3">
					<div id="js-friends">
					
			          <a target="_blank" class="main-nav-link switch-friends-link" href="http://www.ruanyifeng.com/home.html">阮一峰ES6</a>
			        
			          <a target="_blank" class="main-nav-link switch-friends-link" href="http://nodeapi.ucdok.com/api/">NodeJS在线文档</a>
			        
			          <a target="_blank" class="main-nav-link switch-friends-link" href="http://jquery.cuishifeng.cn">jquery在线文档</a>
			        
			          <a target="_blank" class="main-nav-link switch-friends-link" href="http://www.w3school.com.cn/js/">javascript手册</a>
			        
			          <a target="_blank" class="main-nav-link switch-friends-link" href="http://www.phpstudy.net/css3/">css3在线手册</a>
			        
			          <a target="_blank" class="main-nav-link switch-friends-link" href="http://blog.css6.com">凯哥的博客</a>
			        
			        </div>
				</section>
				

				
				
				<section class="switch-part switch-part4">
				
					<div id="js-aboutme">80s，来自祖国最东端乌苏里江畔。爱好运动和音乐，希望在这里可以跟一样爱好前端的朋友共同进步！</div>
				</section>
				
			</div>
		</div>
	</header>				
</div>

    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
  	<div class="overlay">
  		<div class="slider-trigger"></div>
  		<h1 class="header-author js-mobile-header hide">林姐姐</h1>
  	</div>
	<div class="intrude-less">
		<header id="header" class="inner">
			<div class="profilepic">
			
				<img lazy-src="undefined" class="js-avatar">
			
			</div>
			<hgroup>
			  <h1 class="header-author">林姐姐</h1>
			</hgroup>
			
			<p class="header-subtitle">让未来的你的感谢现在的自己！</p>
			
			<nav class="header-menu">
				<ul>
				
					<li><a href="/">主页</a></li>
		        
					<li><a href="/archives">所有文章</a></li>
		        
					<li><a href="/categories/学习笔记/">学习笔记</a></li>
		        
					<li><a href="/categories/技术摘录/">技术摘录</a></li>
		        
		        <div class="clearfix"></div>
				</ul>
			</nav>
			<nav class="header-nav">
				<div class="social">
					
						<a class="github" target="_blank" href="https://github.com/linjieFE" title="github">github</a>
			        
						<a class="mail" target="_blank" href="mailto:solocode@163.com" title="mail">mail</a>
			        
				</div>
			</nav>
		</header>				
	</div>
</nav>

      <div class="body-wrap"><article id="post-react-native-第一个demo" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/2016/10/20/react-native-第一个demo/" class="article-date">
  	<time datetime="2016-10-20T07:18:06.000Z" itemprop="datePublished">2016-10-20</time>
</a>
    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      react-native 第一个demo
    </h1>
  

      </header>
      
      <div class="article-info article-info-post">
        
	<div class="article-tag tagcloud">
		<ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/react-native/">react-native</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/学习笔记/">学习笔记</a></li></ul>
	</div>

        
	<div class="article-category tagcloud">
	<a class="article-category-link" href="/categories/学习笔记/">学习笔记</a>
	</div>


        <div class="clearfix"></div>
      </div>
      
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="React_Native_Mac_u73AF_u5883_u642D_u5EFA"><a href="#React_Native_Mac_u73AF_u5883_u642D_u5EFA" class="headerlink" title="React Native Mac环境搭建"></a>React Native Mac环境搭建</h1><h2 id="1_u3001_u5B89_u88C5Homebrew"><a href="#1_u3001_u5B89_u88C5Homebrew" class="headerlink" title="1、安装Homebrew"></a>1、安装Homebrew</h2><p>安装Homebrew是为安装Node.js做前提准备。<br>安装命令:<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/usr/bin/ruby <span class="operator">-e</span> <span class="string">"<span class="variable">$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)</span>"</span></span><br></pre></td></tr></table></figure></p>
<p>注：可以通过下面命令查看Homebrew是否安装成功<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">brew -v</span><br><span class="line">Homebrew/homebrew-core (git revision <span class="number">93</span>f1; last commit <span class="number">2016</span>-<span class="number">05</span>-<span class="number">23</span>)</span><br></pre></td></tr></table></figure></p>
<h2 id="2_u3001_u5B89_u88C5Node-js"><a href="#2_u3001_u5B89_u88C5Node-js" class="headerlink" title="2、安装Node.js"></a>2、安装Node.js</h2><p>下载双击安装即可：<br>下载地址：<br><a href="https://nodejs.org/en/" target="_blank" rel="external">https://nodejs.org/en/</a><br>Node.js 需要 4.0 及其以上版本。安装好之后，npm 也有了。</p>
<h2 id="3_u3001_u5B89_u88C5React_Native__u547D_u4EE4_u884C_u5DE5_u5177"><a href="#3_u3001_u5B89_u88C5React_Native__u547D_u4EE4_u884C_u5DE5_u5177" class="headerlink" title="3、安装React Native 命令行工具"></a>3、安装React Native 命令行工具</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo npm install -g react-native-cli</span><br></pre></td></tr></table></figure>
<h2 id="4_u3001_u5B89_u88C5Xcode_uFF0C_u4F30_u8BA1iOS_u5F00_u53D1_u7684_u57FA_u672C_u90FD_u5B89_u88C5_u6709"><a href="#4_u3001_u5B89_u88C5Xcode_uFF0C_u4F30_u8BA1iOS_u5F00_u53D1_u7684_u57FA_u672C_u90FD_u5B89_u88C5_u6709" class="headerlink" title="4、安装Xcode，估计iOS开发的基本都安装有."></a>4、安装Xcode，估计iOS开发的基本都安装有.</h2><p>Xcode 7.0 或更高版本下载地 址：<br><a href="https://developer.apple.com/xcode/downloads/" target="_blank" rel="external">https://developer.apple.com/xcode/downloads/</a></p>
<h2 id="5_u3001_u5B89_u88C5_watchman__u548C_flow"><a href="#5_u3001_u5B89_u88C5_watchman__u548C_flow" class="headerlink" title="5、安装 watchman 和 flow"></a>5、安装 watchman 和 flow</h2><p>监控文件变化和类型检查的。安装如下</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">brew install watchman</span><br><span class="line">brew install flow</span><br></pre></td></tr></table></figure>
<h2 id="6_u3001_u521D_u59CB_u5316_u4E00_u4E2A_u9879_u76EE"><a href="#6_u3001_u521D_u59CB_u5316_u4E00_u4E2A_u9879_u76EE" class="headerlink" title="6、初始化一个项目"></a>6、初始化一个项目</h2><p>打开终端，在某个目录下输入命令(这一步会有点慢，耐心等待一下):<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">react-native init HelloWorld</span><br></pre></td></tr></table></figure></p>
<h3 id="u8FD0_u884C_u9879_u76EE"><a href="#u8FD0_u884C_u9879_u76EE" class="headerlink" title="运行项目"></a>运行项目</h3><p><img src="/img/rn-desk.png" alt=""></p>
<p>用XCode打开ios/HelloWorld.xcodeproj文件，点击键盘”⌘-R”或者点击”Run”，编译运行项目。会启动React-Native服务和iOS模拟器。<br>在iOS模拟器中可以看到如图界面：<br><img src="/img/rn_helloworld.png" alt=""></p>
<p>React-Native服务在编写过程中要一直开着 如果不小心把它关了，没关系，可以在终端输入：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm start</span><br></pre></td></tr></table></figure>
<p>来重新开启服务</p>
<p>好了，看到这里，如果你已经成功配置了React-Native的环境，并且新建并成功运行了第一个程序了。那么，就先恭喜了，我们甚至没有写一行代码，就已经成功运行了第一个React-Native的程序，是不是还挺简单的。正所谓，良好的开端是成功的一半。</p>

      
    </div>
    
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2016/10/20/react-环境搭建/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption"><</strong>
      <div class="article-nav-title">
        
          react 环境搭建
        
      </div>
    </a>
  
  
    <a href="/2016/07/12/gulp学习笔记/" id="article-nav-older" class="article-nav-link-wrap">
      <div class="article-nav-title">gulp学习笔记</div>
      <strong class="article-nav-caption">></strong>
    </a>
  
</nav>

  
</article>


<div class="share_jia">
	<!-- JiaThis Button BEGIN -->
	<div class="jiathis_style">
		<span class="jiathis_txt">分享到: &nbsp; </span>
		<a class="jiathis_button_facebook"></a> 
    <a class="jiathis_button_twitter"></a>
    <a class="jiathis_button_plus"></a> 
    <a class="jiathis_button_tsina"></a>
		<a class="jiathis_button_cqq"></a>
		<a class="jiathis_button_douban"></a>
		<a class="jiathis_button_weixin"></a>
		<a class="jiathis_button_tumblr"></a>
    <a href="http://www.jiathis.com/share" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
	</div>
	<script type="text/javascript" src="http://v3.jiathis.com/code/jia.js?uid=1405949716054953" charset="utf-8"></script>
	<!-- JiaThis Button END -->
</div>






<div class="duoshuo">
	<!-- 多说评论框 start -->
	<div class="ds-thread" data-thread-key="react-native-第一个demo" data-title="react-native 第一个demo" data-url="http://yoursite.com/2016/10/20/react-native-第一个demo/"></div>
	<!-- 多说评论框 end -->
	<!-- 多说公共JS代码 start (一个网页只需插入一次) -->
	<script type="text/javascript">
	var duoshuoQuery = {short_name:"true"};
	(function() {
		var ds = document.createElement('script');
		ds.type = 'text/javascript';ds.async = true;
		ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
		ds.charset = 'UTF-8';
		(document.getElementsByTagName('head')[0] 
		 || document.getElementsByTagName('body')[0]).appendChild(ds);
	})();
	</script>
	<!-- 多说公共JS代码 end -->
</div>




</div>
      <footer id="footer">
  <div class="outer">
    <div id="footer-info">
    	<div class="footer-left">
    		&copy; 2016 林姐姐
    	</div>
      	<div class="footer-right">
      		<a href="http://hexo.io/" target="_blank">Hexo</a>  Theme <a href="https://github.com/litten/hexo-theme-yilia" target="_blank">Yilia</a> by Litten
      	</div>
    </div>
  </div>
</footer>
    </div>
    
  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css" type="text/css">


<script>
	var yiliaConfig = {
		fancybox: true,
		mathjax: true,
		animate: true,
		isHome: false,
		isPost: true,
		isArchive: false,
		isTag: false,
		isCategory: false,
		open_in_new: false
	}
</script>
<script src="http://7.url.cn/edu/jslib/comb/require-2.1.6,jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="/js/main.js" type="text/javascript"></script>






<script type="text/x-mathjax-config">
MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
        processEscapes: true,
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    }
});

MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for(i=0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';                 
    }       
});
</script>

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>


  </div>
</body>
</html>